﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SystemDirectory.Biz;
using System.Data;
using SystemDirectory.Common;
using SystemDirectory.Pages.Views;
//using SystemDirectory.Pages.Form;

namespace SystemDirectory.Pages.Views
{

    public partial class PrimiseList : System.Web.UI.Page
    {
        public static bool IsActiveTmp = false;
        public static bool IsCheck = false;
        public static Utilities.SearchType IsSearch;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BOPremise buContact = new BOPremise();
                IsSearch = Utilities.SearchType.TypeAll;
                DataTable dtContact = buContact.Get(IsCheck, IsSearch);
                cbxInactive.Checked = IsActiveTmp;

                //LinkButton9.Attributes.Add("data-toggle", "modal");
                PagedDataSource pds = new PagedDataSource();
                DataView dv = new DataView(dtContact);
                pds.DataSource = dv;
                pds.AllowPaging = true;
                pds.PageSize = 2;
                int NumPage = pds.PageCount;

                int CurrentPage;
                if (Request.QueryString["page"] != null)
                {
                    CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
                }
                else
                {
                    CurrentPage = 1;
                }

                pds.CurrentPageIndex = CurrentPage - 1;

                if (!pds.IsFirstPage)
                    hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
                else
                {

                    hplBackward.Visible = false;
                }
                if (!pds.IsLastPage)
                    hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
                else
                {

                    hplForward.Visible = false;
                }

                rptPremise.DataSource = pds;
                rptPremise.DataBind();
                lblCurrent.Text = CurrentPage.ToString();
                lblTotal.Text = NumPage.ToString();

            }
        }

        protected void cbxInactive_CheckedChanged(object sender, EventArgs e)
        {
            IsActiveTmp = cbxInactive.Checked;
            IsCheck = cbxInactive.Checked;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();


        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeAll;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;
            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }
            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.Type09;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();

        }

        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeAE;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton4_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeFJ;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton5_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeKM;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton6_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeOR;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton7_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeSV;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton8_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeWZ;
            BOPremise buContact = new BOPremise();
            DataTable dtContact = buContact.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtContact);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptPremise.DataSource = pds;
            rptPremise.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();

        }
    }
}